//
//  HttpClientComponent.m
//  UniversalArchitecture
//
//  Created by issuser on 12-10-29.
//  Copyright (c) 2012年 issuser. All rights reserved.
//

#import "FFHttpClientComponent.h"
#import <netinet/in.h>
#import "AFNetworking.h"
#import "FFNetworkCache.h"
#import "FFHttpClientUtil.h"
#import "FFAirCompNetworkLog.h"
//#import "BaseDataManager.h"
//#import "BaseBiz.h"

@interface FFHttpClientComponent()<NSURLSessionDelegate> {
    BOOL useCache;
    BOOL useNetTraffic;

    
    NSTimeInterval requsetTimeOutSeconds;
    
    AFHTTPSessionManager *sessionManager;

}


@property (nonatomic, strong)NSMutableDictionary *requestHeaders;
@property (nonatomic, strong) FFEncryptInterceptor *encryptInterceptor;


@end


@implementation FFHttpClientComponent

- (id)init {
    self = [super init];
    if (self) {
        sessionManager = [AFHTTPSessionManager manager];
        
        AFSecurityPolicy *policy = [AFSecurityPolicy defaultPolicy];
        //如果是需要验证自建证书，需要设置为YES
        policy.allowInvalidCertificates = NO;
        //是否需要验证域名，默认为YES；
        policy.validatesDomainName = YES;
        
        sessionManager.securityPolicy = policy;
        sessionManager.requestSerializer = [AFJSONRequestSerializer serializer];
        sessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
        if (sessionManager.requestSerializer) {
            sessionManager.requestSerializer.timeoutInterval = requsetTimeOutSeconds;
        }
        
        requsetTimeOutSeconds = 10;
        //默认不使用缓存
        useCache = NO;
    }
    return self;
}


- (void)enableDebugLogging:(BOOL)enable{
    [[FFAirCompNetworkLog sharedInstance] enableDebugLogging:enable];
}

- (void)addRequestHeaders:(NSDictionary *)dictionary {
    if (!self.requestHeaders) {
        self.requestHeaders = [[NSMutableDictionary alloc] init];
    }
    NSArray *keys = dictionary.allKeys;
    for (NSString *k in keys) {
        if (dictionary[k]) {
            [self.requestHeaders setValue:dictionary[k] forKey:k];
        }
    }
    
    for (NSString *k in keys) {
        if (dictionary[k]) {
            [sessionManager.requestSerializer setValue:dictionary[k]
                                    forHTTPHeaderField:k];
        }
    }

}

/**
 * 获取http请求返回头
 *
 *  @return 返回头
 */
-(NSDictionary *)getResponseHeaders{

    return self.responseHeaders;
}


- (void)setRequestTimeoutInterval:(NSTimeInterval)timeoutInterval {
    requsetTimeOutSeconds = timeoutInterval;
}


- (void)setUseCache:(BOOL)use {
    useCache = use;
}

- (void)setEncryptInterceptor:(FFEncryptInterceptor *)interceptor{
    _encryptInterceptor = interceptor;
}

- (void)get:(NSString *)url
     params:(NSDictionary *)params
encryptInterceptor:(FFEncryptInterceptor *)interceptor
    success:(RequestSuccessBlock)successHandler
    failure:(RequestFailureBlock)failureHandler {
    NSLog(@"post \nrequest url:%@; \nbody:%@",url,params);
    
    NSData *bodyData = nil;
    NSString *md5Str;
    if (params != nil) {
        bodyData = [NSJSONSerialization dataWithJSONObject:params options:NSJSONWritingPrettyPrinted error:nil];
        md5Str = [FFHttpClientUtil getMD5WithData:bodyData];
    }else{
        md5Str = @"";
    }
    
    

    //是否拿缓存
    if (useCache) {
        // 获取缓存数据
        NSString *result = [[FFNetworkCache sharedNetworkCache] getRespWithURL:url requestBody:md5Str];
        if (nil != result) {
            NSLog(@"post response url=%@; 采用缓存数据， response:%@",url,result);
            if (successHandler) {
                successHandler(result);
            }
            return;
        }
    }
    
    if (![self networkReachable]) {
        NSError *error = [NSError errorWithDomain:FFCNetworkErrorMessage code:FFCNetworkErrorCode userInfo:nil];
        if (failureHandler) {
            failureHandler(error);
        }
        return;
    }
    

    long long reqTime = [[NSDate date] timeIntervalSince1970]*1000;
    
    NSURL *aUrl = [NSURL URLWithString:url];
    //创建请求
    NSMutableURLRequest*request=[NSMutableURLRequest requestWithURL:aUrl cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:requsetTimeOutSeconds];
    //将字符串转换为NSData对象
    [request setHTTPBody:bodyData];
    [request setHTTPMethod:@"GET"];
    for (NSString *key in _requestHeaders) {
        [request setValue:_requestHeaders[key] forHTTPHeaderField:key];
    }
    NSURLSession *session = [NSURLSession sharedSession];
    if ([url hasPrefix:@"https"]) {
        session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[[NSOperationQueue alloc]init]];
    }
    NSURLSessionTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        if (error) {
            if (failureHandler) {
                failureHandler(error);
            }
        }else{
            NSString *responseString = nil;
            if (interceptor) {
                responseString =[[NSString alloc] initWithData:[interceptor decrypt:data] encoding:NSUTF8StringEncoding];
            }else{
                responseString =[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
            }
            NSLog(@"\nresponse url:%@ \nresponse:%@",url,responseString);
            
            //请求成功记录到缓存
            long long respTime = [[NSDate date] timeIntervalSince1970]*1000;
            [[FFNetworkCache sharedNetworkCache] putCacheWithURL:url
                                                     requestBody:md5Str
                                                     requestTime:reqTime
                                                        response:responseString
                                                    responseTime:respTime];
            dispatch_async(dispatch_get_main_queue(), ^{
                if (successHandler) {
                    successHandler(responseString);
                }
                
            });
        }
    }];
    [task resume];
}

/**
 * 发送post请求
 *
 * @param url 请求的网络地址
 * @param params 请求消息字典，无须转换为json
 * @param successHandler 请求成功回调
 * @param failureHandler 请求失败回调
 */
- (void)post:(NSString *)url
      params:(NSDictionary *)params
encryptInterceptor:(FFEncryptInterceptor *)interceptor
     success:(RequestSuccessBlock)successHandler
     failure:(RequestFailureBlock)failureHandler {
    NSData *bodyData = nil;
    NSString *md5Str;
    if (params != nil) {
        NSError *error;
        bodyData = [NSJSONSerialization dataWithJSONObject:params
                                                           options:NSJSONWritingPrettyPrinted
                                                             error:&error];
        if (interceptor) {
            //加密数据
            bodyData = [interceptor encrypt:bodyData];
        }

        md5Str = [FFHttpClientUtil getMD5WithData:bodyData];
    }else{
        md5Str = @"";
    }
    NSLog(@"post \nrequest url:%@; \nbody:%@",url,params);

    //是否拿缓存
    if (useCache) {
        FFNetworkCache *netCacheManager = [FFNetworkCache sharedNetworkCache];
        // 获取缓存数据
        NSString *result = [netCacheManager getRespWithURL:url requestBody:md5Str];
        
        if (nil != result) {
            NSLog(@"post response url=%@; 采用缓存数据， response:%@",url,result);
            if (successHandler) {
                successHandler(result);
            }
            return;
        }
    }
    
    if (![self networkReachable]) {
        NSError *error = [NSError errorWithDomain:FFCNetworkErrorMessage code:FFCNetworkErrorCode userInfo:nil];
        if (failureHandler) {
            failureHandler(error);
        }
        return;
    }
    
    long long reqTime = [[NSDate date] timeIntervalSince1970]*1000;
    
    NSURL *aUrl = [NSURL URLWithString:url];
    //创建请求
    NSMutableURLRequest*request=[NSMutableURLRequest requestWithURL:aUrl cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:requsetTimeOutSeconds];
    //将字符串转换为NSData对象
    [request setHTTPBody:bodyData];
    [request setHTTPMethod:@"POST"];
    for (NSString *key in _requestHeaders) {
        [request setValue:_requestHeaders[key] forHTTPHeaderField:key];
    }
    NSURLSession *session = [NSURLSession sharedSession];
    if ([url hasPrefix:@"https"]) {
        session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[[NSOperationQueue alloc]init]];
    }
    NSURLSessionTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        
        if (error) {
            if (failureHandler) {
                NSLog(@"error : %@",error.description);
                failureHandler(error);
            }
        }else{
            NSString *responseString = nil;
            if (interceptor) {
                responseString =[[NSString alloc] initWithData:[interceptor decrypt:data] encoding:NSUTF8StringEncoding];

            }else{
                responseString =[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
            }
            NSLog(@"\nresponse url:%@ \nresponse:%@",url,responseString);
            
            //请求成功记录到缓存
            long long respTime = [[NSDate date] timeIntervalSince1970]*1000;
            [[FFNetworkCache sharedNetworkCache] putCacheWithURL:url
                                                     requestBody:md5Str
                                                     requestTime:reqTime
                                                        response:responseString
                                                    responseTime:respTime];
            dispatch_async(dispatch_get_main_queue(), ^{
                if (successHandler) {
                    successHandler(responseString);
                }
            });

        }
    }];
    [task resume];
}

#pragma mark -  some config & util


- (BOOL)networkReachable {
    // Create zero addy
    struct sockaddr_in zeroAddress;
    bzero(&zeroAddress, sizeof(zeroAddress));
    zeroAddress.sin_len = sizeof(zeroAddress);
    zeroAddress.sin_family = AF_INET;
    
    // Recover reachability flags
    SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress);
    SCNetworkReachabilityFlags flags;
    
    BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);
    CFRelease(defaultRouteReachability);
    
    if (!didRetrieveFlags)
    {
        return NO;
    }
    
    BOOL isReachable = flags & kSCNetworkFlagsReachable;
    BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired;
    return (isReachable && !needsConnection) ? YES : NO;
}


#pragma mark - NSUrlSessionDelegate

- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler//通过调用block，来告诉NSURLSession要不要收到这个证书
{
    if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]){        NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];//服务器信任证书
        if(completionHandler)
            completionHandler(NSURLSessionAuthChallengeUseCredential,credential);
    }
    
    NSLog(@"....completionHandler---:%@",challenge.protectionSpace.authenticationMethod);
}


/**
 * 发送post请求
 *
 * @param url
 *            请求的网络地址
 * @param params
 *            请求消息字典，无须转换为json，会自动加上统一包体
 * @param successHandler
 *            请求成功回调
 * @param failureHandler
 *            请求失败回调
 */
- (void)sendPOSTRequestWithUrl:(NSString *)url
                        params:(id)params
                       success:(RequestSuccessBlock)successHandler
                       failure:(RequestFailureBlock)failureHandler {
    printf("\n sendPOSTRequestWithUrl = %s \n",url.UTF8String);
    NSString *body = @"";
    if (params != nil) {
        id jsondata = [NSJSONSerialization dataWithJSONObject:params options:NSJSONWritingPrettyPrinted error:nil];
        body = [[NSString alloc] initWithData:jsondata encoding:NSUTF8StringEncoding];
    }
    
    
    
    // NSLog(@"post \nrequest url:%@; \nbody:%@",url,body);
    
    if (![self networkReachable]) {
        
        NSError *error = [NSError errorWithDomain:FFCNetworkErrorMessage
                                             code:FFCNetworkErrorCode
                                         userInfo:@{NSLocalizedDescriptionKey:FFCNetworkErrorMessage}];
        if (failureHandler) {
            failureHandler(error);
        }
        return;
    }
    
    //    long long reqTime = [[NSDate date] timeIntervalSince1970]*1000;
    __block FFHttpClientComponent *component = self;
    [sessionManager.requestSerializer setTimeoutInterval:requsetTimeOutSeconds];
    [sessionManager POST:url
              parameters:params
                progress:nil
                 success:^(NSURLSessionDataTask *task, id responseObject) {
                     NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response;
                     NSDictionary *allHeaders = response.allHeaderFields;
                     component.responseHeaders = allHeaders;
                     NSError *error;
                     component.responseData = responseObject;
                     
                     NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:&error];
                     component.responseDictionary = dic;
                     component.responseData = responseObject;
                     // NSLog(@"responseData原始长度:%lu",(unsigned long)[component.responseData length]);
                     component.responseString =[[NSString alloc] initWithData:component.responseData encoding:NSUTF8StringEncoding];
                     // NSLog(@"\nresponse url:%@ \nresponse:%@",url, component.responseString);
//                     NSString  *rcode = [component.responseDictionary objectForKey:@"code"];
                     
                     if (successHandler) {
                         successHandler(component.responseString);
                     }
                 } failure:^(NSURLSessionDataTask *task, NSError *error) {
                     // NSLog(@"------请求失败-------%@",error);
                     NSError *reError = [NSError errorWithDomain:FFCNetworkErrorMessage
                                                            code:FFCNetworkErrorCode
                                                        userInfo:@{NSLocalizedDescriptionKey:FFCNetworkErrorMessage}];
                     failureHandler(reError);
                 }];
    
}

- (void)sendGETRequestWithUrl:(NSString *)url
                       params:(id)params
                      success:(RequestSuccessBlock)successHandler
                      failure:(RequestFailureBlock)failureHandler {
    
    NSLog(@"get request url=%@",url);
    //    NSString *body = @"";
    //
    //    if (params != nil) {
    //        id jsondata = [NSJSONSerialization dataWithJSONObject:params options:NSJSONWritingPrettyPrinted error:nil];
    //        body = [[NSString alloc] initWithData:jsondata encoding:NSUTF8StringEncoding];
    //    }
    
    if (![self networkReachable]) {
        NSError *error = [NSError errorWithDomain:FFCNetworkErrorMessage code:FFCNetworkErrorCode userInfo:nil];
        if (failureHandler) {
            failureHandler(error);
        }
        return;
    }
    
    [sessionManager.requestSerializer setTimeoutInterval:requsetTimeOutSeconds];
    
    __block FFHttpClientComponent *component = self;
    
    [sessionManager GET:url parameters:params progress:nil
                success:^(NSURLSessionDataTask *task, id responseObject) {
                    NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response;
                    NSDictionary *allHeaders = response.allHeaderFields;
                    component.responseHeaders = allHeaders;
                    NSError *error;
                    component.responseData = responseObject;
                    
                    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:&error];
                    component.responseDictionary = dic;
                    component.responseData = responseObject;
                    NSLog(@"responseData原始长度:%lu",(unsigned long)[component.responseData length]);
                    component.responseString =[[NSString alloc] initWithData:component.responseData encoding:NSUTF8StringEncoding];
                    NSLog(@"\nresponse url:%@ \nresponse:%@",url, component.responseString);
//                    NSString  *rcode = [component.responseDictionary objectForKey:@"code"];
//                    if (rcode && ([rcode integerValue] == 10007 || [rcode integerValue] == 10001)) {
//                        [[NSNotificationCenter defaultCenter] postNotificationName:NOTI_GOTO_LOGIN object:nil userInfo:nil];
//                    }
                    if (successHandler) {
                        successHandler(component.responseString);
                    }
                    
                } failure:^(NSURLSessionDataTask *task, NSError *error) {
                    NSLog(@"------请求失败-------%@",error);
                    if (failureHandler) {
                        
//                        if (error.code == -1001) {
//                            NSError *er = [NSError errorWithDomain:@"连接服务器失败" code:-1001 userInfo:@{@"NSLocalizedDescription":FF_STR(@"common_network_timeout",nil)}];
//                            failureHandler(er);
//                        }else{
//                            NSError *er = [NSError errorWithDomain:@"连接服务器失败" code:-1004 userInfo:@{@"NSLocalizedDescription":FF_STR(@"common_network_ano",nil)}];
//                            failureHandler(er);
//                        }
                    }
                }];
}

- (void)uploadFilesWithUrl:(NSString *)url
                parameters:(NSDictionary *)parameters
                  fileData:(NSData *)fileData
                   success:(RequestUploadSuccessBlock)successHandler
                   failure:(RequestFailureBlock)failureHandler {
    AFHTTPSessionManager *sharedManager = [AFHTTPSessionManager manager];
    sharedManager.requestSerializer = [AFHTTPRequestSerializer serializer];
    sharedManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", @"text/plain",@"image/jpeg",@"image/png",nil];
    sharedManager.requestSerializer.timeoutInterval =20;
#define KEY_ACCOUNT_TOKEN @"accountToken"
    NSString *token = [[NSUserDefaults standardUserDefaults] stringForKey:KEY_ACCOUNT_TOKEN];
    //[sharedManager.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@",[BaseDataManager shareManager].account.token] forHTTPHeaderField:@"Authorization"];
    [sharedManager.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@",token] forHTTPHeaderField:@"Authorization"];
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:0];
    //[dic setObject:[NSString stringWithFormat:@"Bearer %@",[BaseDataManager shareManager].account.token] forKey:@"authorization"];
    [dic setObject:[NSString stringWithFormat:@"Bearer %@",token] forKey:@"authorization"];
    [sharedManager POST:url parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        // 设置时间格式
        formatter.dateFormat = @"yyyyMMddHHmmss";
        NSString *str = [formatter stringFromDate:[NSDate date]];
        NSString *fileName = [NSString stringWithFormat:@"%@.png",str];
        [formData appendPartWithFileData:fileData name:@"file" fileName:fileName mimeType:@"image/png"];
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        NSLog(@"上传进度：%f",uploadProgress.fractionCompleted);
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"上传完成：%@",responseObject);
        successHandler(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        failureHandler(error);
    }];
    

    
}

- (void)uploadFilesWithUrlV2:(NSString *)url
                  parameters:(NSDictionary *)parameters
                    fileData:(NSData *)fileData
                     success:(RequestUploadSuccessBlock)successHandler
                     failure:(RequestFailureBlock)failureHandler{
//    //NSDictionary *headers = @{ @"content-type": @"multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
//                               @"authorization": @"Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiI0N2RmMjNkNzFjNDI0ZmQzYjc5OWQ5MWYyZDk5YzRmZiIsImlhdCI6MTUzNTc4OTI3MywiZXhwIjoxNTM1ODc1NjczfQ.8pafESX4KHCOpRc3fBZkPUh44f9nGujyBTLWNVPb3hI"};
    NSMutableDictionary *headers = [NSMutableDictionary dictionaryWithCapacity:0];
    [headers setObject:@"multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW" forKey:@"content-type"];
#define KEY_ACCOUNT_TOKEN @"accountToken"
    NSString *token = [[NSUserDefaults standardUserDefaults] stringForKey:KEY_ACCOUNT_TOKEN];
    //[headers setObject:[NSString stringWithFormat:@"Bearer %@",[BaseDataManager shareManager].account.token] forKey:@"Authorization"];
    [headers setObject:[NSString stringWithFormat:@"Bearer %@",token] forKey:@"Authorization"];

    //NSArray *parameters = @[  ];
    NSString *boundary = @"----WebKitFormBoundary7MA4YWxkTrZu0gW";
    
    NSError *error;
    NSMutableString *body = [NSMutableString string];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    // 设置时间格式
    formatter.dateFormat = @"yyyyMMddHHmmss";
    NSString *timeStr = [formatter stringFromDate:[NSDate date]];
    NSString *fileName = [NSString stringWithFormat:@"%@.jpeg",timeStr];

    //for (NSDictionary *param in parameters) {
        [body appendFormat:@"--%@\r\n", boundary];
//        if (param[@"fileName"]) {
            [body appendFormat:@"Content-Disposition:form-data; name=\"file\"; filename=\"%@\"\r\n",fileName];
            [body appendFormat:@"Content-Type: %@\r\n\r\n", @"image/jpeg"];
            //[body appendFormat:@"%@", [NSString stringWithContentsOfFile:param[@"fileName"] encoding:NSUTF8StringEncoding error:&error]];
        //NSString *dataStr = [[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding];

            //[body appendFormat:@"%@",fi];

            if (error) {
                NSLog(@"%@", error);
            }
//        } else {
//            [body appendFormat:@"Content-Disposition:form-data; name=\"%@\"\r\n\r\n", param[@"name"]];
//            [body appendFormat:@"%@", param[@"value"]];
//        }
    //}
    //[body appendFormat:@"\r\n--%@--\r\n", boundary];
    //NSData *postData = [body dataUsingEncoding:NSUTF8StringEncoding];
    NSMutableData *postData = [NSMutableData dataWithData:[body dataUsingEncoding:NSUTF8StringEncoding]];
    [postData appendData:fileData];
    NSString *lastStr = [NSString stringWithFormat:@"\r\n--%@--\r\n", boundary];
    [postData appendData:[lastStr dataUsingEncoding:NSUTF8StringEncoding]];
    
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
                                                           cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                       timeoutInterval:10.0];
    [request setHTTPMethod:@"POST"];
    [request setAllHTTPHeaderFields:headers];
    [request setHTTPBody:postData];
    
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                                completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                    if (error) {
                                                        NSLog(@"上传失败%@", error);
                                                        failureHandler(error);

                                                    } else {
                                                        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                        NSLog(@"上传成功%@", httpResponse);
                                                        successHandler(httpResponse);

                                                    }
                                                }];
    [dataTask resume];
}

@end

